//
// Created by lenovo on 2024/2/9.
//

#include "Position2D.h"
#include "PositionTool.h"
#include <cmath>
#include <iostream>
template<>
double magnitude<Position2D> (Position2D p){
    return std::sqrt(p.x*p.x + p.y*p.y);
}

template <>
Position2D normalized(Position2D p){
    double mag = magnitude(p);
    if (mag != 0) {
        return {p.x / mag, p.y / mag};
    } else {
        // 如果长度为零，则返回默认构造的Position2D（可能根据需求进行调整）
        throw std::logic_error("Cannot normalize a Position whose length is ZERO");
    }
}
